package windowFactoryPackage;

import javax.swing.*;

import java.awt.*;
import java.util.ArrayList;

public class PreviousPurchasesWindow extends WindowGenerator{
	//Declare window components
	static ArrayList<JLabel> purchaseNumList = new ArrayList<JLabel>();
	static ArrayList<JLabel> purchaseProgramList = new ArrayList<JLabel>();
	static ArrayList<JLabel> purchasePriceList = new ArrayList<JLabel>();
	private JScrollPane jspDownloads;
	private JPanel mainPanel, numArrayPanel, programArrayPanel, priceArrayPanel;
	
	public PreviousPurchasesWindow(){
		//Set layout for parent JFrame
		setLayout(new BorderLayout());
		
		//Instantiate mainPanel
		mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		
		//Instantiate numArrayPanel, populate Array, add array to panel
		for(int i = 0; i<purchaseProgramList.size(); i++){
			purchaseNumList.add(new JLabel("Purchase " + (i+1) + ": "));
			purchaseNumList.get(i).setBorder(BorderFactory.createEtchedBorder());
		}
		
		numArrayPanel = new JPanel();
		if(purchaseNumList.size() < 10){
			numArrayPanel.setLayout(new GridLayout(10, 0, 10, 10));
		}else{
			numArrayPanel.setLayout(new GridLayout(purchaseNumList.size(), 0, 10, 10));
		}
		
		for(int i = 0; i<purchaseNumList.size(); i++){
			numArrayPanel.add(purchaseNumList.get(i));
		}
		
		mainPanel.add(numArrayPanel, BorderLayout.WEST);
		
		//Instantiate programArrayPanel, populateArray, add array to panel		
		for(int i = 0; i<purchaseProgramList.size(); i++){
			purchaseProgramList.get(i).setBorder(BorderFactory.createEtchedBorder());
		}
		
		programArrayPanel = new JPanel();
		if(purchaseProgramList.size() < 10){
			programArrayPanel.setLayout(new GridLayout(10, 0, 10, 10));
		}else{
			programArrayPanel.setLayout(new GridLayout(purchaseProgramList.size(), 0, 10, 10));
		}
		
		for(int i = 0; i<purchaseProgramList.size(); i++){
			programArrayPanel.add(purchaseProgramList.get(i));
		}
		
		mainPanel.add(programArrayPanel, BorderLayout.CENTER);
		
		//Instantiate priceArrayPanel, populate Array, add array to Panel		
		for(int i = 0; i<purchaseProgramList.size(); i++){
			purchasePriceList.get(i).setBorder(BorderFactory.createEtchedBorder());
		}
		
		priceArrayPanel = new JPanel();
		if(purchasePriceList.size() < 10){
			priceArrayPanel.setLayout(new GridLayout(10, 0, 10, 10));
		}else{
			priceArrayPanel.setLayout(new GridLayout(purchasePriceList.size(), 0, 10, 10));
		}
		
		for(int i = 0; i<purchasePriceList.size(); i++){
			priceArrayPanel.add(purchasePriceList.get(i));
		}
		
		mainPanel.add(priceArrayPanel, BorderLayout.EAST);
		
		//Instantiate JScrollPane and add mainPanel
		jspDownloads = new JScrollPane(mainPanel);
		jspDownloads.getVerticalScrollBar().setUnitIncrement(16);
		
		//Add JScrollPane to parent JFrame
		add(jspDownloads, BorderLayout.CENTER);
	}
}
